﻿using IQIGame.Onigao.GamePlay;
using UnityEditor;

namespace IQIGame.Onigao.Game.Editors
{
    [CustomEditor(typeof(TypewriterText))]
    [CanEditMultipleObjects]
    public class TypewriterTextEditor : ExTextEditor
    {
        private SerializedProperty _speed;
        private SerializedProperty _useAutoSize, _fontWidth, _fontHeight, _lineFontNum;

        protected override void OnEnable()
        {
            base.OnEnable();
            this._speed = serializedObject.FindProperty(nameof(TypewriterText.speed));
            this._useAutoSize = serializedObject.FindProperty(nameof(TypewriterText.useAutoSize));
            this._fontWidth = serializedObject.FindProperty(nameof(TypewriterText.fontWidth));
            this._fontHeight = serializedObject.FindProperty(nameof(TypewriterText.fontHeight));
            this._lineFontNum = serializedObject.FindProperty(nameof(TypewriterText.lineFontNum));
        }

        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            var rTxt = target as TypewriterText;
            if (rTxt == null)
            {
                return;
            }
            rTxt.speed = EditorGUILayout.FloatField("每秒打印字数",this._speed.floatValue);
            rTxt.useAutoSize = EditorGUILayout.Toggle("自动调整大小",this._useAutoSize.boolValue);
            if (rTxt.useAutoSize)
            {
                rTxt.fontWidth = EditorGUILayout.IntField("字宽",this._fontWidth.intValue);
                rTxt.fontHeight = EditorGUILayout.IntField("字高",this._fontHeight.intValue);
                rTxt.lineFontNum = EditorGUILayout.IntField("每行字数",this._lineFontNum.intValue);
            }
        }
    }
}